package org.jtb.quickr;

import org.jdom.Element;

/**
 * Exception representation of a Flickr error response.
 */
public class FlickrResponseException extends QuickrException {  
    private FlickrResponse.Status status;
    private FlickrResponse.ErrorCode errorCode;
    private String errorMessage;

    FlickrResponseException(String msg, FlickrResponse.Status status) {
        super(msg);
        setStatus(status);
    }
    
    FlickrResponseException(String msg, FlickrResponse.Status status, FlickrResponse.ErrorCode errorCode, String errorMessage) {
        super(msg);
        setStatus(status);
        setErrorCode(errorCode);
        setErrorMessage(errorMessage);
    }
    
    /**
     * Get the Flickr error message.
     * @return The error message.
     */
    public String getMessage() {
        StringBuffer b = new StringBuffer(32);
        b.append(super.getMessage());
        b.append(", status: ");
        b.append(getStatus());
        if (getErrorCode() != null) {
            b.append(", error code: ");
            b.append(errorCode);
            b.append(", error messsage: ");
            b.append(getErrorMessage());
        }
        
        return b.toString();
    } 

    /**
     * Get the Flickr error code.
     * @return The error code.
     */
    public FlickrResponse.ErrorCode getErrorCode() {
        return errorCode;
    }

    private void setErrorCode(FlickrResponse.ErrorCode errorCode) {
        this.errorCode = errorCode;
    }

    private String getErrorMessage() {
        return errorMessage;
    }

    private void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * Get status. Note that the status should always be FAIL in this case,
     * assuming that the Flickr services behave as expected.
     * @return The status.
     */
    public FlickrResponse.Status getStatus() {
        return status;
    }

    private void setStatus(FlickrResponse.Status status) {
        this.status = status;
    }
}
